<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <router-view></router-view>
        <button @click="$router.push('/')">页面一</button><button @click="$router.push({path: '/page2', query: {
            id: 1,
            name: '张三'
        }})">页面二</button>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-router.js"></script>
    <script>

        const page1 = {
            template: `
                <div>这是页面一</div>
            `
        }

        const page2 = {
            template: `
                <div>这是页面二</div>
            `,
            created() {
                console.log(this.$route);
            }
        }

        const routes = [
            {
                path: '/',
                name: 'page1',
                component: page1
            },
            {
                path: '/page2',
                name: 'page2',
                component: page2
            }
        ]

            // console.log(VueRouter.prototype);
        let routerPush = VueRouter.prototype.push
        VueRouter.prototype.push = function push(location) {
            if(typeof(location)=="string"){
                var Separator = "&";
                if(location.indexOf('?')==-1) { Separator='?'; }
                location = location + Separator + "random=" + new Date().getTime();
            }
            return routerPush.call(this, location).catch(error=> error)
        }
        const router = new VueRouter({
            routes
        })

        new Vue({
            el: "#app",
            router
        })
    </script>
</body>
</html>